/*
package com.itcast.mq.msg;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

*/
/**
 * @Author Administrator
 * @Date 2021/11/21:11:11
 * @Description:
 *//*

@Slf4j
public class Producer {

    private static final String TOPIC = "milo2";
    private static final String BROKER_LIST = "localhost:9092";
    private static KafkaProducer<String,String> producer = null;

    */
/*
    初始化生产者
     *//*

    static {
        Properties configs = initConfig();
        producer = new KafkaProducer<String, String>(configs);
    }

    */
/*
    初始化配置
     *//*

    private static Properties initConfig(){
        Properties properties = new Properties();
        properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,BROKER_LIST);
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
        return properties;
    }

    public static void main(String[] args) throws InterruptedException {
        //消息实体
        ProducerRecord<String , String> record = null;
        for (int i = 0; i < 1000; i++) {
            record = new ProducerRecord<String, String>(TOPIC, "key", "value:"+i);
            //发送消息
            producer.send(record, new Callback() {
                @Override
                public void onCompletion(RecordMetadata recordMetadata, Exception e) {
                    if (null != e){
                        log.info("send error" + e.getMessage());
                    }else {
                        // System.out.println(String.format("offset:%s,partition:%s",recordMetadata.offset(),recordMetadata.partition()));
                        // System.out.println("toString: " + recordMetadata.toString());
                        System.out.println(JSON.toJSONString(recordMetadata));
                    }
                }
            });
        }
        producer.close();
    }

}
*/
